package ace.cmp.util;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;

/**
 * @author Caspar
 */
public final class AceLocalDateTimeUtils {
  public static final LocalDateTime MIN_MYSQL = LocalDateTime.of(0000, 1, 1, 0, 0, 0);
  public static final LocalDateTime MAX_MYSQL = LocalDateTime.of(9999, 12, 31, 23, 59, 59);

  /**
   * 转成timestamp
   *
   * @param localDateTime
   * @return
   */
  public static Long toTimestamp(LocalDateTime localDateTime) {
    ZoneId zone = ZoneId.systemDefault();
    Instant instant = localDateTime.atZone(zone).toInstant();
    return instant.toEpochMilli();
  }

  /**
   * 从timestamp 转成LocalDateTime
   *
   * @param timestamp
   * @return
   */
  public static LocalDateTime fromTimestamp(Long timestamp) {
    Instant instant = Instant.ofEpochMilli(timestamp);
    ZoneId zone = ZoneId.systemDefault();
    return LocalDateTime.ofInstant(instant, zone);
  }
}
